Authentication and Authorization

Learn how to authenticate your requests and manage API keys securely

← Back to Documentation Home

All requests to the Weather API must be authenticated with an API key. Authentication ties usage to your account and enforces plan limits.

Prerequisites

Get your API key

1

Sign in to the dashboard

Sign in to the OpenWeather dashboard.

2

Create a new key

Go to API KeysCreate Key.

3

Store securely

Copy the generated key and store it securely.

4

Add a label (Optional)

Add a label/description to track usage.

If a key is exposed or you suspect misuse, revoke it and create a new one immediately.

Base URL

https://api.openweathermap.org/data/2.5

Ways to send your key

OpenWeather requires the key to be passed as the appid query parameter.

Standard usage

Append appid=YOUR_API_KEY to the request URL.

# Replace YOUR_API_KEY first API_KEY=YOUR_API_KEY curl -s "https://api.openweathermap.org/data/2.5/weather?q=San%20Francisco,US&units=metric&appid=$API_KEY"

Note: Unlike some APIs, OpenWeather does not accept the key in an Authorization header. Always use the appid parameter.

Make a test request (copy‑ready)

This verifies your key is valid and your network can reach the API.

API_KEY=YOUR_API_KEY curl -s "https://api.openweathermap.org/data/2.5/weather?q=San%20Francisco,US&units=metric&appid=$API_KEY"

Expected response (truncated)

{ "coord": { "lon": -122.4194, "lat": 37.7749 }, "weather": [{ "id": 802, "main": "Clouds", "description": "scattered clouds" }], "main": { "temp": 18.2, "feels_like": 17.5, "humidity": 72 }, "name": "San Francisco" }

Apply API key restrictions

Reduce risk by limiting where and how your key can be used.

Keys without restrictions are easier to abuse. Add restrictions before deploying to production.

Key scope and limits

Security best practices

Error responses

Authentication and authorization errors return standardized JSON. Use the HTTP status to branch handling logic.

401 Unauthorized — missing/invalid key

HTTP/1.1 401 Unauthorized Content-Type: application/json { "cod": 401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info." }

429 Too Many Requests — rate limit exceeded

HTTP/1.1 429 Too Many Requests Content-Type: application/json Retry-After: 60 { "cod": 429, "message": "You have exceeded the allowed number of requests." }

What's next

s